/**
 * Created by winter on 2017-03-27.
 */
module.exports = function ($http, httpservice) {
  var caseBarWriteService = {
    getFolders: getFolders,
    createFolderPort: createFolderPort,
    deleteFolder: deleteFolder,
    filesUpload: filesUpload,
    fileRename: fileRename,
    fileDownload: fileDownload,
    fileDelete: fileDelete,
    filePreview: filePreview,
    deleteEvidenceAttr: deleteEvidenceAttr,
  };
  return caseBarWriteService;
  //获取文件列表
  function getFolders(caseId) {
    return $http({
      url: httpservice.getFolderUrl,
      method: "POST",
      params: {caseId: caseId}
    })
  };
  //创建文件夹
  function createFolderPort(params) {
    return $http({
      method:"POST",
      url:httpservice.createFolderUrl,
      params:params,
    })
  };
  //文件夹的删除
  function deleteFolder(params) {
    return $http({
      method:"POST",
      url:httpservice.deleteFolderUrl,
      params:params,
    })
  };
  //删除文件
  // function deleteUpFile(params) {
  //   return $http({
  //     method:"POST",
  //     url:httpservice.deleteUpFileUrl,
  //     params:params,
  //   })
  // };
  function fileDelete(params) {
    return $http({
      method:"POST",
      url:httpservice.fileDeleteUrl,
      params:params,
    })
  };
  //新删除文件
  function deleteEvidenceAttr (params) {
    return $http({
      method:"POST",
      url:httpservice.deleteEvidenceAttrUrl,
      data:params,
      headers : {'Content-Type':'application/json'}
    })
  }
  //文件上传
  function filesUpload(fileData) {
    return $http({
      method:"POST",
      url:httpservice.fileUpUrl,
      headers: {'Content-Type': undefined},
      transformRequest: angular.identity,
      data:fileData,
    })
  }
  //文件夹重命名
  function fileRename(params) {
    return $http({
      method:'POST',
      url:httpservice.fileRenameUrl,
      params:params,
    })
  };
  //文件下载
  function fileDownload(params) {
    return $http({
      method:'GET',
      url:httpservice.fileDownloadUrl,
      params:params,
      responseType: 'arraybuffer',
      headers : {'Content-Type':'application/json'}
    })
  };
  //文件预览
  function filePreview(params){
    return $http({
      method:'POST',
      url:httpservice.filePreviewUrl,
      params:params,
      responseType: 'arraybuffer',
      headers : {'Content-Type':'application/json'}
    })
  };
};
